package com.coffee.core;

import lombok.*;

import java.io.Serializable;


/**
 * @author: songkui
 * @since: 2024/4/15 14:56
 */
@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class CoffeeResponse<T> implements Serializable {

    private int state;
    private int opcode;
    private String message;
    private T data;

    public static  <T> CoffeeResponse<T> response(ResponseCode responseCode){
        return response(null, responseCode);
    }
    public static  <T> CoffeeResponse<T> success(){
        return response(null, CoffeeResponseEnum.Success);
    }
    public static <T> CoffeeResponse<T> responseSuccess(T data){
        return response(data, CoffeeResponseEnum.Success);
    }

    public static <T> CoffeeResponse<T> response(T data, ResponseCode responseCode){
        return new CoffeeResponse<>(responseCode.code(), responseCode.opcode(),   responseCode.message(), data);
    }

    public static <T> CoffeeResponse<T> responseMessage(int state, String message){
        return new CoffeeResponse<>(state, 0,   message, null);
    }
    public boolean judgeSuccess(){
        return CoffeeResponseEnum.Success.code() == this.state;
    }

    public boolean judgeFailure(){
        return CoffeeResponseEnum.Success.code() != this.state;
    }

}